﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Collections;
using MS.Core.Base.Transaction;
using System.Collections.Specialized;
using LHS.Core.TableInfo;
using MS.Core.Constants.Objects;

namespace LHS.Win
{
    public partial class frmYTaLapMoi : Form
    {
        #region variables
        LHS.Core.Clinical.ClinicalController objController = new LHS.Core.Clinical.ClinicalController();
        private string _strDienBienBenh = string.Empty;
        private DateTime _dteExaminationDate;
        #endregion
        // Methods
        /// <summary>
        /// Form nay la do y ta login vao,
        /// sau do qua ben danh sach ho so ben an
        /// lap moi mot benh an
        /// </summary>
        /// <param name="clrISN"></param>
        /// <param name="NhanBiet"></param>
        /// <param name="PatISN"></param>
        public frmYTaLapMoi(string clrISN, string NhanBiet, string PatISN)
        {
            this.InitializeComponent();
            this._clrISN = clrISN;
            this._NhanBiet = NhanBiet;
            this._patISN = PatISN;
        }

        #region Button Click
        private void btAdd_Click(object sender, EventArgs e)
        {
            this.treeView1_DoubleClick(sender, e);
        }

        private void btLuuBenhAn_Click(object sender, EventArgs e)
        {
            if (this.CheckData())
            {
                if ((this.tbPhone.Text.Length > 0) && !this.IsNumber(this.tbPhone.Text.ToString()))
                {
                    MessageBox.Show("Số điện thoại không hợp lệ", "Lỗi nhập", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                }
                else if ((this.tbDiDong.Text.Length > 0) && !this.IsNumber(this.tbDiDong.Text.ToString()))
                {
                    MessageBox.Show("Số điện thoại di động không hợp lệ", "Lỗi nhập", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                }
                else
                {
                    string str;
                    string str2;
                    string str4;
                    if (this.tbMach.Text.Length > 0)
                    {
                        if (!this.IsNumber(this.tbMach.Text.ToString()))
                        {
                            MessageBox.Show("Mạch không hợp lệ", "Lỗi nhập", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                            return;
                        }
                        str = this.tbMach.Text.ToString();
                    }
                    else
                    {
                        str = "0";
                    }
                    if (this.tbNhietDo.Text.Length > 0)
                    {
                        if (!this.IsFloat(this.tbNhietDo.Text.ToString()))
                        {
                            MessageBox.Show("Nhiệt độ không hợp lệ", "Lỗi nhập", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                            return;
                        }
                        str2 = this.tbNhietDo.Text.ToString();
                    }
                    else
                    {
                        str2 = "0";
                    }
                    if (this.tbCanNang.Text.Length > 0)
                    {
                        if (!this.IsFloat(this.tbCanNang.Text.ToString()))
                        {
                            MessageBox.Show("Cân nặng không hợp lệ", "Lỗi nhập", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                            return;
                        }
                        str4 = this.tbCanNang.Text.ToString();
                    }
                    else
                    {
                        str4 = "0";
                    }
                    string str3 = this.tbHuyetAp.Text.ToString();
                    string str5 = this.rbMale.Checked ? "Nam" : "Nữ";

                    TransactionManager trans = TransactionManager.ThreadTransactionMgr();
                    try
                    {
                        trans.BeginTransaction();
                         
                        ///kiểm tra clrISN có lần khám và lần tái khám đó chưa, nếu có rồi thì get mã clrISN đó ra
                        ///và lệnh này trở thành cập nhật bệnh án
                        ///edit by thaoht 201001108
                        bool blnIsUpdated = false;
                        ListDictionary param4Check = new ListDictionary();
                        param4Check.Add(InfoClinicalRecord.PATISN,this._patISN);
                        param4Check.Add(InfoClinicalRecord.CLREXAMINATIONTIMES,this.tbLanKham.Text);
                        param4Check.Add(InfoClinicalRecord.CLRREXAMINATIONTIMES,this.txtTaiKham.Text);
                        object objclrISN = objController.GetScalar(InfoClinicalRecord.CLRISN, param4Check, InfoClinicalRecord.TABLENAME);
                        if (objclrISN is Int64)
                        {
                            blnIsUpdated = true; //cap nhat benh an cu
                            this.clrISN = objclrISN.ToString();
                        }
                        else
                        {
                            objclrISN = objController.GetIDENT_CURRENT(InfoClinicalRecord.TABLENAME); /// tao benh an moi
                            this.clrISN = Convert.ToString((int)(Convert.ToInt64(objclrISN) + 1));
                        }

                        ArrayList list = new ArrayList();
                        ArrayList list2 = new ArrayList();
                        ArrayList list3 = new ArrayList();
                        int count = this.listView1.Items.Count;
                        for (int i = 0; i < count; i++)
                        {
                            string str6 = this.listView1.Items[i].Text.ToString();
                            switch (this.listView1.Items[i].ForeColor.Name.ToString())
                            {
                                case "Red":
                                    list3.Add(0);
                                    break;

                                case "Blue":
                                    list3.Add(1);
                                    break;

                                case "Purple":
                                    list3.Add(2);
                                    break;

                                case "Green":
                                    list3.Add(3);
                                    break;

                                case "Gray":
                                    list3.Add(4);
                                    break;
                            }
                            list.Add(str6);
                        }

                        DataTable dtSick;
                        List<ExpressionObject> paramSick = new List<ExpressionObject>();
                        for (int j = 0; j < list.Count; j++)
                        {
                            paramSick.Clear();
                            paramSick.Add(new ExpressionObject(InfoSicks.SCKNAME, list[j].ToString()));
                            dtSick = objController.GetData(InfoSicks.TABLENAME, paramSick);
                            if (dtSick.Rows.Count > 0)
                                list2.Add(dtSick.Rows[0][0].ToString());
                        }

                        //xoa ClinicalSick theo CLRISN
                        List<ExpressionObject> paramDelClinicalSick = new List<ExpressionObject>();
                        paramDelClinicalSick.Add(new ExpressionObject(InfoClinicalSick.CLRISN,this.clrISN));
                        objController.DeleteRow(InfoClinicalSick.TABLENAME, paramDelClinicalSick);

                        DataTable dtClinicalSicks = InfoClinicalSick.GetStructure();
                        DataRow drClinicalSicks;
                        for (int k = 0; k < list2.Count; k++)
                        {
                            drClinicalSicks = dtClinicalSicks.NewRow();
                            drClinicalSicks[InfoClinicalSick.CLRISN] = this.clrISN;
                            drClinicalSicks[InfoClinicalSick.SCKISN] = list2[k].ToString();
                            drClinicalSicks[InfoClinicalSick.SCKSICKLEVEL] = list3[k].ToString();
                            dtClinicalSicks.Rows.Add(drClinicalSicks);
                            objController.InsertRow(drClinicalSicks,new string[] {});
                        }

                        string str8 = string.Empty;
                        if (this.txtTaiKham.Text.Equals("0"))
                        {
                            str8 = "0";
                        }
                        else
                        {
                            str8 = "1";
                        }

                        ///get thong tin phau thuat cua lan kham dang duoc chon hien tai
                        string strSURGERY = string.Empty;
                        string strNgayMo = string.Empty;
                        try
                        {
                            string strLanKham = "0";
                            if (cbLanKham.Visible == false)
                            {
                                strLanKham = tbLanKham.Text;
                            }
                            else
                            {
                                strLanKham = cbLanKham.SelectedItem.ToString();
                            }
                            DataTable dtSurgicalInfo = objController.getSurgicalInfo(this.tbID.Text, int.Parse(strLanKham));
                            if (dtSurgicalInfo != null && dtSurgicalInfo.Rows.Count > 0)
                            {
                                DataRow drSurgicalInfo = dtSurgicalInfo.Rows[0];
                                strSURGERY = drSurgicalInfo[InfoClinicalRecord.CLRSURGERY].ToString();
                                if (!string.IsNullOrEmpty(drSurgicalInfo[InfoClinicalRecord.CLRAPPOINTMENTDATE].ToString()))
                                {
                                    strNgayMo = drSurgicalInfo[InfoClinicalRecord.CLRAPPOINTMENTDATE].ToString();
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Class.ShowException(ex);
                        }

                        ListDictionary paramClinicalRecordNurse_Insert = new ListDictionary();
                        paramClinicalRecordNurse_Insert.Add(InfoPatients.PATID,this.tbID.Text);
                        paramClinicalRecordNurse_Insert.Add(InfoPatients.PATNAME,this.tbFullName.Text);
                        paramClinicalRecordNurse_Insert.Add(InfoPatients.PATBIRTHDATE,this.dtpBirthDay.Value);
                        paramClinicalRecordNurse_Insert.Add(InfoPatients.PATAGE,this.tbTuoi.Text);
                        paramClinicalRecordNurse_Insert.Add(InfoPatients.PATSEX,str5);
                        paramClinicalRecordNurse_Insert.Add(InfoPatients.PATADDRESS,this.tbAddress.Text);
                        paramClinicalRecordNurse_Insert.Add(InfoPatients.PATTEL,this.tbPhone.Text);
                        paramClinicalRecordNurse_Insert.Add(InfoPatients.PATOCCUPATION,this.tbJob.Text);
                        paramClinicalRecordNurse_Insert.Add(InfoClinicalRecord.EMPISN,"1");
                        paramClinicalRecordNurse_Insert.Add(InfoClinicalRecord.CLRPULSE,str);
                        paramClinicalRecordNurse_Insert.Add(InfoClinicalRecord.CLRTEMPERATURE,str2);
                        paramClinicalRecordNurse_Insert.Add(InfoClinicalRecord.CLRBLOODPRESSURE,str3);
                        paramClinicalRecordNurse_Insert.Add(InfoClinicalRecord.CLRWEIGH,str4);
                        paramClinicalRecordNurse_Insert.Add(InfoClinicalRecord.CLRMEDICALHISTORY,this.tbTienCan.Text);
                        paramClinicalRecordNurse_Insert.Add(InfoClinicalRecord.CLRTEST,string.Empty);
                        paramClinicalRecordNurse_Insert.Add(InfoClinicalRecord.CLRSICKNOTINLIST,this.tbBenhNgoaiDS.Text);
                        paramClinicalRecordNurse_Insert.Add(InfoClinicalRecord.CLREXAMINATIONTIMES,this.tbLanKham.Text);
                        paramClinicalRecordNurse_Insert.Add(InfoClinicalRecord.CLREXAMINATIONDATE,DateTime.Now);
                        paramClinicalRecordNurse_Insert.Add(InfoClinicalRecord.CLRSKILL,string.Empty);
                        paramClinicalRecordNurse_Insert.Add(InfoClinicalRecord.CLRMEDICALADVICE,string.Empty);
                        paramClinicalRecordNurse_Insert.Add(InfoClinicalRecord.CLRFOLLOWUPEXAMINATIONDATE,DateTime.Now);
                        paramClinicalRecordNurse_Insert.Add(InfoClinicalRecord.CLRPICTURE,string.Empty);
                        paramClinicalRecordNurse_Insert.Add(InfoClinicalRecord.CLRSURGERY, strSURGERY);
                        paramClinicalRecordNurse_Insert.Add(InfoPatients.PATMOBILE,this.tbDiDong.Text);
                        paramClinicalRecordNurse_Insert.Add(InfoClinicalRecord.CLRSICKHISTORY,string.Empty);
                        paramClinicalRecordNurse_Insert.Add(InfoClinicalRecord.CLRREXAMINATIONTIMES,this.txtTaiKham.Text);
                        paramClinicalRecordNurse_Insert.Add(InfoClinicalRecord.CLRREXAMINATIONSTATUS,str8);
                        paramClinicalRecordNurse_Insert.Add(InfoClinicalRecord.CLRTYPE, rbTMH.Checked == true? "1" :"2"); //edit here 20090606 ; 1=TMH;2=TM
                        paramClinicalRecordNurse_Insert.Add(InfoClinicalRecord.CLRREXAMINATION4SURGERY, string.Empty);
                        paramClinicalRecordNurse_Insert.Add(InfoClinicalRecord.CLRAPPOINTMENTDATE, strNgayMo); //edit here 20090830
                        paramClinicalRecordNurse_Insert.Add(InfoClinicalRecord.CLRSICKCHANGE, _strDienBienBenh); //edit here 20091017

                        objController.Exec_StoreProc("sp_Patients_ClinicalRecordNurse_Insert",paramClinicalRecordNurse_Insert);
                      
                        if (str8 == "1")
                        {
                            int num5 = 0;
                            if (int.Parse(this.txtTaiKham.Text) > 1)
                            {
                                num5 = int.Parse(this.txtTaiKham.Text) - 1;
                            }

                            List<ExpressionObject> paramGetPathologicalClinical = new List<ExpressionObject>();
                            paramGetPathologicalClinical.Add(new ExpressionObject(InfoClinicalRecord.CLREXAMINATIONTIMES,this.tbLanKham.Text));
                            paramGetPathologicalClinical.Add(new ExpressionObject(InfoPatients.PATID, this.tbID.Text));
                            paramGetPathologicalClinical.Add(new ExpressionObject(InfoClinicalRecord.CLRREXAMINATIONTIMES, num5 ));
                           DataTable dtGetPathologicalClinical= objController.GetData("vw_PathologicalClinical", paramGetPathologicalClinical);
                           
                            if (dtGetPathologicalClinical == null || dtGetPathologicalClinical.Rows.Count == 0 ||string.IsNullOrEmpty(dtGetPathologicalClinical.Rows[0][InfoPathologicalSigns.PLSPATHOLOGICALSIGNS].ToString()) == true)
                            {
                                this.btLuuBenhAn.Enabled = false;
                                this.btTaiKham.Enabled = false;
                                return;
                            }

                            ArrayList list4 = new ArrayList();
                            for (int m = 0; m < dtGetPathologicalClinical.Rows.Count; m++)
                            {
                                list4.Add(dtGetPathologicalClinical.Rows[m][InfoPathologicalSigns.PLSPATHOLOGICALSIGNS].ToString());
                            }
                            string str9 = dtGetPathologicalClinical.Rows[0][InfoPathologicalOutList.POLPATHOLOGICALSIGNSOUTLIST].ToString();

                            //xoa trong PathologicalClinical theo clrISN
                            List<ExpressionObject> paramDelPathologicalClinical = new List<ExpressionObject>();
                            paramDelPathologicalClinical.Add(new ExpressionObject(InfoPathologicalClinical.CLRISN, this.clrISN));
                            objController.DeleteRow(InfoPathologicalClinical.TABLENAME, paramDelPathologicalClinical);

                            List<ExpressionObject> paramGetPathologicalOutList = new List<ExpressionObject>();
                            paramGetPathologicalOutList.Add(new ExpressionObject(InfoPathologicalOutList.CLRISN, this.clrISN));
                            DataTable dtPathologicalOutList = objController.GetData(InfoPathologicalOutList.TABLENAME, paramGetPathologicalOutList);

                            if (dtPathologicalOutList == null || dtPathologicalOutList.Rows.Count == 0)
                            {
                                ListDictionary paramPathologicalOutList = new ListDictionary();
                                paramPathologicalOutList.Add(InfoPathologicalOutList.CLRISN, this.clrISN);
                                paramPathologicalOutList.Add(InfoPathologicalOutList.POLPATHOLOGICALSIGNSOUTLIST, str9);
                                objController.Exec_StoreProc("sp_PathologicalOutList_Insert", paramPathologicalOutList);
                            }

                            //Get data từ bảng PathologicalSigns
                            ArrayList list5 = new ArrayList();
                            List<ExpressionObject> paramPathologicalSigns = new List<ExpressionObject>();
                            DataTable dtPathologicalSigns;
                            for (int n = 0; n < list4.Count; n++)
                            {
                                paramPathologicalSigns.Clear();
                                paramPathologicalSigns.Add(new ExpressionObject(InfoPathologicalSigns.PLSPATHOLOGICALSIGNS, list4[n].ToString()));
                                dtPathologicalSigns = objController.GetData(InfoPathologicalSigns.TABLENAME, paramPathologicalSigns);
                                if (dtPathologicalSigns.Rows.Count > 0)
                                    list5.Add(dtPathologicalSigns.Rows[0][0].ToString());
                            }

                            // insert vao bang PathologicalClinical
                            DataTable dtPathologicalClinical = InfoPathologicalClinical.GetStructure();
                            DataRow drPathologicalClinical;
                            for (int num8 = 0; num8 < list5.Count; num8++)
                            {
                                drPathologicalClinical = dtPathologicalClinical.NewRow();
                                drPathologicalClinical[InfoPathologicalClinical.CLRISN] = this.clrISN;
                                drPathologicalClinical[InfoPathologicalClinical.PLSISN] = list5[num8].ToString();
                                dtPathologicalClinical.Rows.Add(drPathologicalClinical);
                                objController.InsertRow(drPathologicalClinical, new string[] { });
                            }

                            ListDictionary paramUpdPathologicalOutList = new ListDictionary();
                            paramUpdPathologicalOutList.Add(InfoClinicalRecord.CLRISN, this.clrISN);
                            paramUpdPathologicalOutList.Add(InfoPathologicalOutList.POLPATHOLOGICALSIGNSOUTLIST, str9);
                            objController.Exec_StoreProc("sp_PathologicalOutList_Update", paramUpdPathologicalOutList);

                            ListDictionary paramClinicalPathologicalSign = new ListDictionary();
                            paramClinicalPathologicalSign.Add(InfoClinicalRecord.CLRISN, this.clrISN);
                            objController.Exec_StoreProc("sp_ClinicalPathologicalSign_Update", paramClinicalPathologicalSign);
                        }
                        this.btLuuBenhAn.Enabled = false;

                        ///save thông tin tiền căn
                        ///edit by thaoht 20100108
                        if (blnIsUpdated == false) //neu insert moi thi tao moi tien can
                        {
                            ucTienCan.resetExtraID1(clrISN);
                        }
                        ucTienCan.Save();

                        trans.CommitTransaction();
                        MessageBox.Show("Hồ sơ bệnh án đã được lưu", "Lưu hồ sơ bệnh án thành công", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    }
                    catch (Exception ex)
                    {
                        trans.RollbackTransaction();
                        Class.ShowException(ex);
                    }

                }
            }
        }

        private void btRemove_Click(object sender, EventArgs e)
        {
            this.listView1_DoubleClick(sender, e);
        }

        /// <summary>
        /// nut lap benh an moi
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btReset_Click(object sender, EventArgs e)
        {
            this.rbMale.Checked = true;
            this.tbBenhNgoaiDS.Text = "";
            this.tbMach.Text = "";
            this.tbNhietDo.Text = "";
            this.tbHuyetAp.Text = "";
            this.tbCanNang.Text = "";
            this.btLuuBenhAn.Enabled = true;
            this.tbLanKham.Visible = true;
            this.cbLanKham.Visible = false;
            int count = this.cbLanKham.Items.Count;
            this.cbLanKham.SelectedIndex = count - 1;
            this.tbLanKham.Text = Convert.ToString((int)(short.Parse(this.cbLanKham.Text) + 1));

            LoadDienBienBenh(int.Parse(this.tbLanKham.Text), 0); //edit 20091017

            this.listView1.Items.Clear();
            this.cboTaiKham.Visible = false;
            this.txtTaiKham.Visible = true;
            this.txtTaiKham.Text = "0";
            this.btTaiKham.Enabled = false;
            this.btReset.Enabled = false;
        }

        private void btTaiKham_Click(object sender, EventArgs e)
        {
            this.rbMale.Checked = true;
            this.tbBenhNgoaiDS.Text = "";
            this.tbMach.Text = "";
            this.tbNhietDo.Text = "";
            this.tbHuyetAp.Text = "";
            this.tbCanNang.Text = "";
            this.btLuuBenhAn.Enabled = true;
            this.tbLanKham.Visible = true;
            this.cbLanKham.Visible = false;
            this.tbLanKham.Text = this.cbLanKham.Text;
            //can tim ra ngay kham cua lan tai kham truoc do.
            if (_dteExaminationDate.ToString("yyyyMMdd") == DateTime.Now.ToString("yyyyMMdd"))
            {//vi luc nay khong phai la lap benh an moi ma chi la cap nhat benh an 
                if (this.cboTaiKham.Visible) // da co tai kham cho lan kham hien tai
                {
                    int num2 = this.cbLanKham.FindString(this.tbLanKham.Text);
                    this.cbLanKham.SelectedIndex = num2;
                    this.cbLanKham_SelectedIndexChanged(null, null);
                    int count = this.cboTaiKham.Items.Count;
                    this.cboTaiKham.SelectedIndex = count - 1;
                    this.txtTaiKham.Text = this.cboTaiKham.Text;
                }
            }
            else
            {
                if (this.txtTaiKham.Visible) //truong hop nay khi chua tai kham cho lan kham hien tai
                {
                    this.txtTaiKham.Text = (int.Parse(this.txtTaiKham.Text) + 1).ToString();
                }
                if (this.cboTaiKham.Visible) // da co tai kham cho lan kham hien tai
                {
                    int num2 = this.cbLanKham.FindString(this.tbLanKham.Text);
                    this.cbLanKham.SelectedIndex = num2;
                    this.cbLanKham_SelectedIndexChanged(null, null);
                    int count = this.cboTaiKham.Items.Count;
                    this.cboTaiKham.SelectedIndex = count - 1;
                    this.txtTaiKham.Text = Convert.ToString((int)(int.Parse(this.cboTaiKham.Text) + 1));
                }
                LoadDienBienBenh(int.Parse(this.tbLanKham.Text),int.Parse(this.txtTaiKham.Text)); //edit 20091017

                ///load lai thong tin TIEN CAN
                ///edit by thaoht 20100107
                ///1. lay ra ma benh an truoc lan tai kham va lan kham moi nhat
                DataTable dtLatestCLRISN = objController.Getfn_MaxRexamTimesOFMaxExamTimesNoJoinMedExport(tbID.Text, this.tbLanKham.Text, this.txtTaiKham.Text);
                if (dtLatestCLRISN.Rows.Count == 0 || string.IsNullOrEmpty(dtLatestCLRISN.Rows[0][InfoClinicalRecord.OLDCLRISN].ToString()))
                    loadThongTinTienCan("-9999");//= clrISN// 4 load benh an moi -- muc dich la xoa het du lieu trong cac control duoc sinh dong
                else
                    loadThongTinTienCan(dtLatestCLRISN.Rows[0][InfoClinicalRecord.OLDCLRISN].ToString());
            }


            this.txtTaiKham.Visible = true;
            this.cboTaiKham.Visible = false;
            this.btReset.Enabled = false;
            this.btTaiKham.Enabled = false;
            int num4 = 0;
            if (int.Parse(this.txtTaiKham.Text) > 1)
            {
                num4 = int.Parse(this.txtTaiKham.Text) - 1;
            }

            List<ExpressionObject> param = new List<ExpressionObject>();
            param.Add(new ExpressionObject(InfoClinicalRecord.CLREXAMINATIONTIMES, this.tbLanKham.Text));
            param.Add(new ExpressionObject(InfoPatients.PATID, this.tbID.Text));
            param.Add(new ExpressionObject(InfoClinicalRecord.CLRREXAMINATIONTIMES, num4));
            DataTable dt = objController.GetData("vw_PathologicalClinical", param);

            if (dt == null || dt.Rows.Count == 0 || dt.Rows[0][InfoPathologicalSigns.PLSPATHOLOGICALSIGNS].ToString() == "")
            {
                MessageBox.Show("Không thể tái khám tiếp khi bệnh án chưa được bác sĩ thông qua", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                this.btLuuBenhAn.Enabled = false;
                this.btTaiKham.Enabled = false;
            }
        }

        private void btThoat_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        #endregion

        private void frmYTaLapMoi_Load(object sender, EventArgs e)
        {
            this.LoadCayBenh();
            this.loadTienIch(); //edit here 20090910
            if (this._NhanBiet == "0") // chac chan se khong roi vao truong hop nay
            {
                ArrayList arrColumn = new ArrayList();
                arrColumn.Add(InfoPatients.PATID);
                arrColumn.Add(InfoPatients.PATNAME);
                arrColumn.Add(InfoPatients.PATBIRTHDATE);
                arrColumn.Add(InfoClinicalRecord.CLRPULSE);
                arrColumn.Add(InfoClinicalRecord.CLRTEMPERATURE);
                arrColumn.Add(InfoClinicalRecord.CLRBLOODPRESSURE);
                arrColumn.Add(InfoClinicalRecord.CLRWEIGH);
                arrColumn.Add(InfoPatients.PATSEX);
                arrColumn.Add(InfoPatients.PATADDRESS);
                arrColumn.Add(InfoPatients.PATAGE);
                arrColumn.Add(InfoPatients.PATTEL);
                arrColumn.Add(InfoPatients.PATOCCUPATION);
                arrColumn.Add(InfoClinicalRecord.CLREXAMINATIONTIMES);
                arrColumn.Add(InfoPatients.PATMOBILE);
                arrColumn.Add(InfoClinicalRecord.CLRSURGERY);
                arrColumn.Add(InfoClinicalRecord.CLRSICKCHANGE); //20091017
                arrColumn.Add(InfoClinicalRecord.CLREXAMINATIONDATE); //20091017
                List<ExpressionObject> paramPatients = new List<ExpressionObject>();
                paramPatients.Add(new ExpressionObject(InfoPatients.PATISN, this._patISN));
                DataTable dt = objController.GetData("vw_SearchClinicalRecord", arrColumn, paramPatients);
                if (dt != null && dt.Rows.Count > 0)
                {
                    DataRow dr = dt.Rows[0];
                    this.tbID.Text = dr[InfoPatients.PATID].ToString();
                    this.tbFullName.Text = dr[InfoPatients.PATNAME].ToString();
                    this.dtpBirthDay.Value = DateTime.Parse(dr[InfoPatients.PATBIRTHDATE].ToString());
                    if (dr[InfoClinicalRecord.CLRPULSE].ToString() == "0")
                    {
                        this.tbMach.Text = "";
                    }
                    else
                    {
                        this.tbMach.Text = dr[InfoClinicalRecord.CLRPULSE].ToString();
                    }
                    if (dr[InfoClinicalRecord.CLRTEMPERATURE].ToString() == "0")
                    {
                        this.tbNhietDo.Text = "";
                    }
                    else
                    {
                        this.tbNhietDo.Text = dr[InfoClinicalRecord.CLRTEMPERATURE].ToString();
                    }
                    if (dr[InfoClinicalRecord.CLRBLOODPRESSURE].ToString() == "0")
                    {
                        this.tbHuyetAp.Text = "";
                    }
                    else
                    {
                        this.tbHuyetAp.Text = dr[InfoClinicalRecord.CLRBLOODPRESSURE].ToString();
                    }
                    if (dr[InfoClinicalRecord.CLRWEIGH].ToString() == "0")
                    {
                        this.tbCanNang.Text = "";
                    }
                    else
                    {
                        this.tbCanNang.Text = dr[InfoClinicalRecord.CLRWEIGH].ToString();
                    }
                    if (dr[InfoPatients.PATSEX].ToString() == "Nam")
                    {
                        this.rbMale.Checked = true;
                    }
                    else
                    {
                        this.rbFemale.Checked = true;
                    }
                    this.tbAddress.Text = dr[InfoPatients.PATADDRESS].ToString();
                    this.tbPhone.Text = dr[InfoPatients.PATTEL].ToString();
                    this.tbJob.Text = dr[InfoPatients.PATOCCUPATION].ToString();
                    this.tbDiDong.Text = dr[InfoPatients.PATMOBILE].ToString();
                    _strDienBienBenh = dr[InfoClinicalRecord.CLRSICKCHANGE].ToString(); //20091017
                    _dteExaminationDate = DateTime.Parse(dr[InfoClinicalRecord.CLREXAMINATIONDATE].ToString()); //20091017
                    this.tbLanKham.Text = "1";
                    this.tbLanKham.Visible = true;
                    this.cbLanKham.Visible = false;
                    this.btLuuBenhAn.Enabled = true;
                    this.dtpBirthDay_Leave(sender,e); // thaoht edit by 20090509

                    ///load lai thong tin TIEN CAN theo benh an duoc chon
                    ///edit by thaoht 20100108
                    loadThongTinTienCan("-9999"); // chac chan se khong roi vao truong hop nay
                }
            }
            else
            {
                this.tbLanKham.Text = "1";
                this.tbLanKham.Visible = false;
                this.cbLanKham.Visible = true;
                this.btReset.Visible = true;
                this.btLuuBenhAn.Enabled = false;

                ArrayList arrColumn = new ArrayList();
                arrColumn.Add(InfoClinicalRecord.CLREXAMINATIONTIMES);
                List<ExpressionObject> param = new List<ExpressionObject>();
                param.Add(new ExpressionObject(InfoClinicalRecord.PATISN, this._patISN));
                DataTable table2 = objController.GetData(InfoClinicalRecord.TABLENAME, true, arrColumn, param);

                if ((table2 != null && table2.Rows.Count > 0) && (table2.Rows[0][InfoClinicalRecord.CLREXAMINATIONTIMES].ToString() == string.Empty || table2.Rows[0][InfoClinicalRecord.CLREXAMINATIONTIMES].ToString() == ""))
                {
                    this.tbLanKham.Text = "1";
                    this.tbLanKham.Visible = true;
                    this.cbLanKham.Visible = false;
                }
                else
                {
                    this.cbLanKham.DisplayMember = InfoClinicalRecord.CLREXAMINATIONTIMES;
                    this.cbLanKham.DataSource = table2;
                    this.cbLanKham.SelectedIndex = this.cbLanKham.Items.Count - 1;
                }
                ///20100108
                //this.cbLanKham_SelectedIndexChanged(null, null); -- edit by thaoht comment vi this.cbETimes.SelectedIndex = this.cbETimes.Items.Count - 1; --> da chay ham cboETimes_selectedindexchanged roi
            }
        }

        #region Other Utility

        private void LoadDienBienBenh(int intLanKham, int intLanTaiKham)
        {
            /* -	Phần diễn biến bệnh thì chèn vào lần khám và tái khám. Sau mỗi lần tái khám thì máy tự động chèn vào: BS khám chỉ chèn nội dung vào thôi
             -	VD:
             1.	Lần khám 1:
             1.1.	Lần tái khám 0 (ngày/tháng/năm): 
             1.2.	Lần tái khám 1 (ngày/tháng/năm):
             1.3.	Lần tái khám 2 (ngày/tháng/năm):
             2.	Lần khám 2:
             2.1.	 Lần tái khám 0 (ngày/tháng/năm): 
             2.2.	Lần tái khám 1 (ngày/tháng/năm):
             2.3.	Lần tái khám 2 (ngày/tháng/năm): */
            if (intLanKham == 1 && intLanTaiKham == 0)
            {}
            else
            {
                _strDienBienBenh += "\r\n";
            }
            if (intLanTaiKham == 0)
            {
                _strDienBienBenh += intLanKham.ToString() + ". Lần khám " + intLanKham.ToString() + ": \r\n";
            }
            
            _strDienBienBenh += intLanKham.ToString() + "." + (intLanTaiKham + 1).ToString() + ". \t Lần tái khám " + intLanTaiKham.ToString() + " (" + DateTime.Now.ToString("dd/MM/yyyy") + "): \r\n";
        }

        private void insertChildNode(string strName)
        {
            this.node.Nodes.Add(strName);
        }

        private void insertParentNode(string strName)
        {
            this.node = new TreeNode(strName);
        }

        private bool CheckData()
        {
            if (this.tbFullName.Text == "")
            {
                MessageBox.Show("Vui lòng nhập họ và tên", "Lỗi Nhập", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            if ((this.tbTuoi.Text == "") || (Convert.ToInt64(this.tbTuoi.Text.ToString()) < 0L))
            {
                MessageBox.Show("Vui lòng chọn ngày sinh hợp lệ", "Lỗi Nhập", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            if (this.tbAddress.Text == "")
            {
                MessageBox.Show("Vui lòng nhập địa chỉ", "Lỗi Nhập", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            if ((this.listView1.Items.Count <= 0) && (this.tbBenhNgoaiDS.Text == ""))
            {
                MessageBox.Show("Vui lòng chọn triệu chứng", "Lỗi Nhập", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            return true;
        }

        private bool IsFloat(string Number)
        {
            try
            {
                float.Parse(Number);
                return true;
            }
            catch
            {
                return false;
            }
        }

        private bool IsNumber(string Number)
        {
            try
            {
                decimal.Parse(Number);
                return true;
            }
            catch
            {
                return false;
            }
        }

        private void LoadCayBenh()
        {
            ArrayList list = new ArrayList();
            ArrayList list2 = new ArrayList();
            DataTable table = objController.GetSickTree();
            if (table != null)
            {
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    list.Add(table.Rows[i][0].ToString());
                    list2.Add(table.Rows[i][1].ToString());
                }
                ListDictionary orderby = new ListDictionary();
                orderby.Add(InfoSicks.SCKNAME, "asc");
                List<ExpressionObject> param = new List<ExpressionObject>();
                for (int j = 0; j < list.Count; j++)
                {
                    this.insertParentNode(list2[j].ToString());

                    param.Clear();
                    param.Add(new ExpressionObject(InfoSicks.SKTISN, list[j].ToString()));
                    DataTable table2 = objController.GetData(InfoSicks.TABLENAME, param, orderby);

                    for (int k = 0; k < table2.Rows.Count; k++)
                    {
                        this.insertChildNode(table2.Rows[k][2].ToString());
                    }
                    this.treeView1.Nodes.Add(this.node);
                }
            }
        }

        #endregion

        #region Event
        private void cbLanKham_SelectedIndexChanged(object sender, EventArgs e)
        {
            ArrayList arrCoClinicalRecord = new ArrayList();
            arrCoClinicalRecord.Add(InfoClinicalRecord.CLRREXAMINATIONSTATUS);
            arrCoClinicalRecord.Add(InfoClinicalRecord.CLRREXAMINATIONTIMES);
            List<ExpressionObject> param = new List<ExpressionObject>();
            param.Add(new ExpressionObject(InfoPatients.PATISN, this._patISN));
            param.Add(new ExpressionObject(InfoClinicalRecord.CLREXAMINATIONTIMES, this.cbLanKham.Text));
            DataTable dtClinicalRecord = objController.GetData(InfoClinicalRecord.TABLENAME, true, arrCoClinicalRecord, param);
            if (dtClinicalRecord == null || dtClinicalRecord.Rows.Count == 0)
                return;
            if (dtClinicalRecord.Rows[0][InfoClinicalRecord.CLRREXAMINATIONSTATUS].ToString() == string.Empty || dtClinicalRecord.Rows.Count == 1)
            {
                this.txtTaiKham.Text = "0";
                this.txtTaiKham.Visible = true;
                this.cboTaiKham.Visible = false;
            }
            else
            {
                this.btTaiKham.Enabled = true;
                this.txtTaiKham.Visible = false;
                this.cboTaiKham.Visible = true;
                this.cboTaiKham.Items.Clear();

                for (int i = 0; i < dtClinicalRecord.Rows.Count; i++)
                {
                    this.cboTaiKham.Items.Add(dtClinicalRecord.Rows[i][InfoClinicalRecord.CLRREXAMINATIONTIMES].ToString());
                }
                this.cboTaiKham.SelectedIndex = this.cboTaiKham.Items.Count - 1;
                return;
            }
            ArrayList arrCoPatient = new ArrayList();
            arrCoPatient.Add(InfoPatients.PATID);
            arrCoPatient.Add(InfoPatients.PATNAME);
            arrCoPatient.Add(InfoPatients.PATAGE);
            arrCoPatient.Add(InfoPatients.PATSEX);
            arrCoPatient.Add(InfoPatients.PATADDRESS);
            arrCoPatient.Add(InfoPatients.PATTEL);
            arrCoPatient.Add(InfoPatients.PATOCCUPATION);
            arrCoPatient.Add(InfoClinicalRecord.CLRPULSE);
            arrCoPatient.Add(InfoClinicalRecord.CLRTEMPERATURE);
            arrCoPatient.Add(InfoClinicalRecord.CLRBLOODPRESSURE);
            arrCoPatient.Add(InfoClinicalRecord.CLRWEIGH);
            arrCoPatient.Add(InfoClinicalRecord.CLRMEDICALHISTORY);
            arrCoPatient.Add(InfoClinicalRecord.CLRTEST);
            arrCoPatient.Add(InfoClinicalRecord.CLRSICKNOTINLIST);
            arrCoPatient.Add(InfoClinicalRecord.CLRPATHOLOGICALSIGNS);
            arrCoPatient.Add(InfoClinicalRecord.CLREXAMINATIONTIMES);
            arrCoPatient.Add(InfoClinicalRecord.CLRSKILL);
            arrCoPatient.Add(InfoClinicalRecord.CLRDOCTORPRESCRIPTION);
            arrCoPatient.Add(InfoClinicalRecord.CLRMEDICALADVICE);
            arrCoPatient.Add(InfoPatients.PATBIRTHDATE);
            arrCoPatient.Add(InfoClinicalRecord.CLREXAMINATIONDATE);
            arrCoPatient.Add(InfoClinicalRecord.CLRFOLLOWUPEXAMINATIONDATE);
            arrCoPatient.Add(InfoEmployees.EMPNAME);
            arrCoPatient.Add(InfoClinicalRecord.CLRPICTURE);
            arrCoPatient.Add(InfoClinicalRecord.CLRISN);
            arrCoPatient.Add(InfoPatients.PATMOBILE);
            arrCoPatient.Add(InfoClinicalRecord.CLRSURGERY);
            arrCoPatient.Add(InfoClinicalRecord.CLRAPPOINTMENTDATE);
            arrCoPatient.Add(InfoClinicalRecord.CLRSICKCHANGE);
            arrCoPatient.Add(InfoClinicalRecord.CLRSICKHISTORY);
            arrCoPatient.Add(InfoClinicalRecord.CLRTYPE);//edit here 20090606 
            DataTable dt = objController.GetData("vw_ClinicalRecord", arrCoPatient, param);

            if (dt != null && dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                this.tbID.Text = dr[InfoPatients.PATID].ToString();
                this.tbFullName.Text = dr[InfoPatients.PATNAME].ToString();

                if (dr[InfoPatients.PATSEX].ToString() == "Nam")
                {
                    this.rbMale.Checked = true;
                }
                else
                {
                    this.rbFemale.Checked = true;
                }
                this.tbAddress.Text = dr[InfoPatients.PATADDRESS].ToString();
                this.tbPhone.Text = dr[InfoPatients.PATTEL].ToString();
                this.tbJob.Text = dr[InfoPatients.PATOCCUPATION].ToString();
                if (dr[InfoClinicalRecord.CLRPULSE].ToString() == "0")
                {
                    this.tbMach.Text = "";
                }
                else
                {
                    this.tbMach.Text = dr[InfoClinicalRecord.CLRPULSE].ToString();
                }
                if (dr[InfoClinicalRecord.CLRTEMPERATURE].ToString() == "0")
                {
                    this.tbNhietDo.Text = "";
                }
                else
                {
                    this.tbNhietDo.Text = dr[InfoClinicalRecord.CLRTEMPERATURE].ToString();
                }
                if (dr[InfoClinicalRecord.CLRBLOODPRESSURE].ToString() == "0")
                {
                    this.tbHuyetAp.Text = "";
                }
                else
                {
                    this.tbHuyetAp.Text = dr[InfoClinicalRecord.CLRBLOODPRESSURE].ToString();
                }
                if (dr[InfoClinicalRecord.CLRWEIGH].ToString() == "0")
                {
                    this.tbCanNang.Text = "";
                }
                else
                {
                    this.tbCanNang.Text = dr[InfoClinicalRecord.CLRWEIGH].ToString();
                }
                this.tbTienCan.Text = dr[InfoClinicalRecord.CLRMEDICALHISTORY].ToString();
                this.tbBenhNgoaiDS.Text = dr[InfoClinicalRecord.CLRSICKNOTINLIST].ToString();
                this.dtpBirthDay.Value = DateTime.Parse(dr[InfoPatients.PATBIRTHDATE].ToString());
                this.dtpBirthDay_Leave(sender, e);
                this.tbDiDong.Text = dr[InfoPatients.PATMOBILE].ToString();
                _strDienBienBenh = dr[InfoClinicalRecord.CLRSICKCHANGE].ToString(); //20091017
                _dteExaminationDate = DateTime.Parse(dr[InfoClinicalRecord.CLREXAMINATIONDATE].ToString()); //20091017

                ///load lai thong tin TIEN CAN theo benh an duoc chon
                ///edit by thaoht 20100108
                loadThongTinTienCan(dr[InfoClinicalRecord.CLRISN].ToString());

                //edit here 20090606
                rbTMH.Checked = string.IsNullOrEmpty(dr[InfoClinicalRecord.CLRTYPE].ToString()) == true || dr[InfoClinicalRecord.CLRTYPE].ToString() == "1" ? true : false; //1 : TMH ; 2: TM
                rbTM.Checked = !rbTMH.Checked;

                DataTable dtClinicalSicks = objController.GetData("vw_ClinicalSicks", param);

                if (dtClinicalSicks != null)
                {
                    this.listView1.Items.Clear();
                    for (int j = 0; j < dtClinicalSicks.Rows.Count; j++)
                    {
                        ListViewItem item = new ListViewItem(dtClinicalSicks.Rows[j][InfoSicks.SCKNAME].ToString());
                        switch (dtClinicalSicks.Rows[j][InfoClinicalSick.SCKSICKLEVEL].ToString())
                        {
                            case "0":
                                item.ForeColor = Color.Red;
                                break;

                            case "1":
                                item.ForeColor = Color.Blue;
                                break;

                            case "2":
                                item.ForeColor = Color.Purple;
                                break;

                            case "3":
                                item.ForeColor = Color.Green;
                                break;

                            case "4":
                                item.ForeColor = Color.Gray;
                                break;
                        }
                        this.listView1.Items.AddRange(new ListViewItem[] { item });
                    }
                }
            }
        }

        private void cboTaiKham_SelectedIndexChanged(object sender, EventArgs e)
        {
            ArrayList arrCoPatient = new ArrayList();
            arrCoPatient.Add(InfoPatients.PATID);
            arrCoPatient.Add(InfoPatients.PATNAME);
            arrCoPatient.Add(InfoPatients.PATAGE);
            arrCoPatient.Add(InfoPatients.PATSEX);
            arrCoPatient.Add(InfoPatients.PATADDRESS);
            arrCoPatient.Add(InfoPatients.PATTEL);
            arrCoPatient.Add(InfoPatients.PATOCCUPATION);
            arrCoPatient.Add(InfoClinicalRecord.CLRPULSE);
            arrCoPatient.Add(InfoClinicalRecord.CLRTEMPERATURE);
            arrCoPatient.Add(InfoClinicalRecord.CLRBLOODPRESSURE);
            arrCoPatient.Add(InfoClinicalRecord.CLRWEIGH);
            arrCoPatient.Add(InfoClinicalRecord.CLRMEDICALHISTORY);
            arrCoPatient.Add(InfoClinicalRecord.CLRTEST);
            arrCoPatient.Add(InfoClinicalRecord.CLRSICKNOTINLIST);
            arrCoPatient.Add(InfoClinicalRecord.CLRPATHOLOGICALSIGNS);
            arrCoPatient.Add(InfoClinicalRecord.CLREXAMINATIONTIMES);
            arrCoPatient.Add(InfoClinicalRecord.CLRSKILL);
            arrCoPatient.Add(InfoClinicalRecord.CLRDOCTORPRESCRIPTION);
            arrCoPatient.Add(InfoClinicalRecord.CLRMEDICALADVICE);
            arrCoPatient.Add(InfoPatients.PATBIRTHDATE);
            arrCoPatient.Add(InfoClinicalRecord.CLREXAMINATIONDATE);
            arrCoPatient.Add(InfoClinicalRecord.CLRFOLLOWUPEXAMINATIONDATE);
            arrCoPatient.Add(InfoEmployees.EMPNAME);
            arrCoPatient.Add(InfoClinicalRecord.CLRPICTURE);
            arrCoPatient.Add(InfoClinicalRecord.CLRISN);
            arrCoPatient.Add(InfoPatients.PATMOBILE);
            arrCoPatient.Add(InfoClinicalRecord.CLRSURGERY);
            arrCoPatient.Add(InfoClinicalRecord.CLRAPPOINTMENTDATE);
            arrCoPatient.Add(InfoClinicalRecord.CLRSICKCHANGE);
            arrCoPatient.Add(InfoClinicalRecord.CLRSICKHISTORY);
            arrCoPatient.Add(InfoClinicalRecord.CLRTYPE); //edit here 20090606

            List<ExpressionObject> param = new List<ExpressionObject>();
            param.Add(new ExpressionObject(InfoPatients.PATISN, this._patISN));
            param.Add(new ExpressionObject(InfoClinicalRecord.CLREXAMINATIONTIMES, this.cbLanKham.Text));
            param.Add(new ExpressionObject(InfoClinicalRecord.CLRREXAMINATIONTIMES, this.cboTaiKham.Text));
            DataTable dt = objController.GetData("vw_ClinicalRecord", arrCoPatient, param);

            if (dt != null && dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                this.tbID.Text = dr[InfoPatients.PATID].ToString();
                this.tbFullName.Text = dr[InfoPatients.PATNAME].ToString();
                if (dr[InfoPatients.PATSEX].ToString() == "Nam")
                {
                    this.rbMale.Checked = true;
                }
                else
                {
                    this.rbFemale.Checked = true;
                }
                this.tbAddress.Text = dr[InfoPatients.PATADDRESS].ToString();
                this.tbPhone.Text = dr[InfoPatients.PATTEL].ToString();
                this.tbJob.Text = dr[InfoPatients.PATOCCUPATION].ToString();
                if (dr[InfoClinicalRecord.CLRPULSE].ToString() == "0")
                {
                    this.tbMach.Text = "";
                }
                else
                {
                    this.tbMach.Text = dr[InfoClinicalRecord.CLRPULSE].ToString();
                }
                if (dr[InfoClinicalRecord.CLRTEMPERATURE].ToString() == "0")
                {
                    this.tbNhietDo.Text = "";
                }
                else
                {
                    this.tbNhietDo.Text = dr[InfoClinicalRecord.CLRTEMPERATURE].ToString();
                }
                if (dr[InfoClinicalRecord.CLRBLOODPRESSURE].ToString() == "0")
                {
                    this.tbHuyetAp.Text = "";
                }
                else
                {
                    this.tbHuyetAp.Text = dr[InfoClinicalRecord.CLRBLOODPRESSURE].ToString();
                }
                if (dr[InfoClinicalRecord.CLRWEIGH].ToString() == "0")
                {
                    this.tbCanNang.Text = "";
                }
                else
                {
                    this.tbCanNang.Text = dr[InfoClinicalRecord.CLRWEIGH].ToString();
                }
                this.tbTienCan.Text = dr[InfoClinicalRecord.CLRMEDICALHISTORY].ToString();
                this.tbBenhNgoaiDS.Text = dr[InfoClinicalRecord.CLRSICKNOTINLIST].ToString();
                this.dtpBirthDay.Value = DateTime.Parse(dr[InfoPatients.PATBIRTHDATE].ToString());
                this.dtpBirthDay_Leave(sender, e);
                this.tbDiDong.Text = dr[InfoPatients.PATMOBILE].ToString();

                _strDienBienBenh = dr[InfoClinicalRecord.CLRSICKCHANGE].ToString(); //20091017
                _dteExaminationDate = DateTime.Parse(dr[InfoClinicalRecord.CLREXAMINATIONDATE].ToString()); //20091017

                ///load lai thong tin TIEN CAN theo benh an duoc chon
                ///edit by thaoht 20100108
                loadThongTinTienCan(dr[InfoClinicalRecord.CLRISN].ToString());

                //edit here 20090606
                rbTMH.Checked = string.IsNullOrEmpty(dr[InfoClinicalRecord.CLRTYPE].ToString()) == true || dr[InfoClinicalRecord.CLRTYPE].ToString() == "1" ? true : false; //1 : TMH ; 2: TM
                rbTM.Checked = !rbTMH.Checked;

                DataTable dtClinicalSicks = objController.GetData("vw_ClinicalSicks", param);

                if (dtClinicalSicks != null)
                {
                    this.listView1.Items.Clear();
                    for (int j = 0; j < dtClinicalSicks.Rows.Count; j++)
                    {
                        ListViewItem item = new ListViewItem(dtClinicalSicks.Rows[j][InfoSicks.SCKNAME].ToString());
                        switch (dtClinicalSicks.Rows[j][InfoClinicalSick.SCKSICKLEVEL].ToString())
                        {
                            case "0":
                                item.ForeColor = Color.Red;
                                break;

                            case "1":
                                item.ForeColor = Color.Blue;
                                break;

                            case "2":
                                item.ForeColor = Color.Purple;
                                break;

                            case "3":
                                item.ForeColor = Color.Green;
                                break;

                            case "4":
                                item.ForeColor = Color.Gray;
                                break;
                        }
                        this.listView1.Items.AddRange(new ListViewItem[] { item });
                    }
                }
            }
        }

        private void listView1_DoubleClick(object sender, EventArgs e)
        {
            if (this.listView1.SelectedItems.Count > 0)
            {
                ListViewItem item = this.listView1.SelectedItems[0];
                this.listView1.Items.Remove(item);
            }
        }

        private void listView1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                frmBangMau mau = new frmBangMau();
                mau.ShowInTaskbar = false;
                mau.ShowDialog();
                if (this.listView1.SelectedItems.Count > 0)
                {
                    ListViewItem item = this.listView1.SelectedItems[0];
                    ListViewItem item2 = new ListViewItem(item.Text.ToString());
                    if (Class.mau == "Red")
                    {
                        item2.ForeColor = Color.Red;
                    }
                    if (Class.mau == "Green")
                    {
                        item2.ForeColor = Color.Green;
                    }
                    if (Class.mau == "Purple")
                    {
                        item2.ForeColor = Color.Purple;
                    }
                    if (Class.mau == "Blue")
                    {
                        item2.ForeColor = Color.Blue;
                    }
                    if (Class.mau == "Gray")
                    {
                        item2.ForeColor = Color.Gray;
                    }
                    this.listView1.Items.AddRange(new ListViewItem[] { item2 });
                    this.listView1.Items.Remove(item);
                }
            }
        }

        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.listView1.SelectedItems.Count > 0)
            {
                ListViewItem item = this.listView1.SelectedItems[0];
                this.toolTip1.SetToolTip(this.listView1, item.Text.ToString());
            }
        }

        private void treeView1_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                string str = this.treeView1.SelectedNode.Text.ToString();
                int count = 0;
                int num2 = 0;
                if (!this.treeView1.SelectedNode.Parent.IsSelected)
                {
                    count = this.listView1.Items.Count;
                    if (count == 0)
                    {
                        ListViewItem item = new ListViewItem(this.treeView1.SelectedNode.Text.ToString());
                        item.ForeColor = Color.Gray;
                        this.listView1.Items.AddRange(new ListViewItem[] { item });
                    }
                    else
                    {
                        for (int i = 0; i < count; i++)
                        {
                            if (str == this.listView1.Items[i].Text.ToString())
                            {
                                num2++;
                            }
                        }
                        if (num2 == 0)
                        {
                            ListViewItem item2 = new ListViewItem(this.treeView1.SelectedNode.Text.ToString());
                            item2.ForeColor = Color.Gray;
                            this.listView1.Items.AddRange(new ListViewItem[] { item2 });
                        }
                    }
                }
            }
            catch
            {
            }
        }

        private void dtpBirthDay_Leave(object sender, EventArgs e)
        {
            this.tbTuoi.Text = (Convert.ToInt32(DateTime.Now.Year) - Convert.ToInt32(dtpBirthDay.Value.Year)).ToString();
        }

        #endregion

        #region Context Menu Event
        private void AddTienCan(object sender, EventArgs e)
        {
            if (this.tbTienCan.Text == "")
            {
                this.tbTienCan.Text = "- " + sender.ToString();
            }
            else
            {
                this.tbTienCan.Text = this.tbTienCan.Text + "\r\n- " + sender.ToString();
            }
            Point pos = new Point(12, 0x18);
            ctmTienCan.Show(tbTienCan, pos);
        }
        private void AddNgheNghiep(object sender, EventArgs e)
        {
            this.tbJob.Text = sender.ToString();
            Point pos = new Point(12, 0x18);
            ctmNgheNghiep.Show(this.tbJob, pos);
        }

        private void loadTienIch()
        {
            //load them tien can, nghe nghiep,
            ArrayList paramValue = new ArrayList();
            paramValue.Add((int)InfoFacility.eFacilityType._eTienCan);
            paramValue.Add((int)InfoFacility.eFacilityType._eNgheNghiep);
            List<ExpressionObject> param = new List<ExpressionObject>();
            param.Add(new ExpressionObject(InfoFacility.FACTYPE, paramValue, ExpressionObject.eSelectOperator.In));
            DataTable dtFacility = objController.GetData(InfoFacility.TABLENAME, param);
            foreach (DataRow drFacility in dtFacility.Rows)
            {
                switch (int.Parse(drFacility[InfoFacility.FACTYPE].ToString()))
                {
                    case (int)InfoFacility.eFacilityType._eNgheNghiep:
                        this.ctmNgheNghiep.Items.Add(drFacility[InfoFacility.FACNAME].ToString());
                        this.ctmNgheNghiep.Items[this.ctmNgheNghiep.Items.Count - 1].Click += new EventHandler(this.AddNgheNghiep);
                        break;
                    case (int)InfoFacility.eFacilityType._eTienCan:
                        this.ctmTienCan.Items.Add(drFacility[InfoFacility.FACNAME].ToString());
                        this.ctmTienCan.Items[this.ctmTienCan.Items.Count - 1].Click += new EventHandler(this.AddTienCan);
                        break;
                }
            }
        }

        #endregion

        #region TienCan

        private void loadThongTinTienCan(string _strClrISN)
        {
            this.ucTienCan.PatientID = this._patISN;
            string surISN = "-9999"; // 4 Tien Can //20091216
            this.ucTienCan.SurgicalID = surISN;
            this.ucTienCan.ExtraID1 = _strClrISN;
            this.ucTienCan.getData();
        }
        #endregion
    }
}